<script>
import {getCoursedetail} from "@/api";
import index from "vuex";
import HeaderPage from "@/components/headerPage.vue";
import FooterPage from "@/components/footerPage.vue";

export default {
  name: "courseDetail",
  components: {FooterPage, HeaderPage},
  computed: {
    index() {
      return index
    }
  },
  data() {
    return {

      form: {
        commentContent: '',
        score: null
      },
      activeName: 'first',
      ids: '',
      courseList: '',
      sectionsList: ''
    }
  },
  created() {
    // this.$route.params.id
    this.getCourseList()
  },
  mounted() {
    this.getCourseList()
  },
  methods: {
    onSubmit() {
      console.log('submit!');
    },
    handleClick(tab, event) {
      console.log(tab, event);
    },
    getCourseList() {
      this.ids = this.$route.params.id
      getCoursedetail(this.ids).then(res => {
        this.courseList = res.data
        console.log(this.courseList.sections)
        this.sectionsList = this.courseList.sections
      })
    }
  }
}
</script>

<template>
  <div class="course-detail">
    <!--存放头部-->
    <div>
      <header-page></header-page>
    </div>
    <!--详情页面-->
    <div class="detai-main">
      <div class="ruoter-box"></div>
      <div class="course-box">
        <!--图片-->
        <div class="img-box">
          <img :src="courseList.coverFileUrl" alt="" srcset="">
        </div>
        <!--内容-->
        <div>
          <!--课程标题-->
          <div class="course-title">{{ courseList.courseSubtitle }}</div>
          <!--学习人数以及评分-->
          <div class="ppeople-ralo">
            <span>共有{{ courseList.participationsCount }}人学习</span>
          </div>
          <!--          <div>{{ courseList }}</div>-->
        </div>
        <div></div>
      </div>
    </div>
    <!-- table切换-->
    <div class="table-box">
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="课程描述" name="first">
          <div v-html="courseList.courseDetail"></div>
        </el-tab-pane>
        <el-tab-pane label="目录" name="second">
          <div class="mulu-box" style="background-color: white;padding: 30px">
            <div v-for="(item,index) in sectionsList" :key="item.sectionId">
              <h3 class="title"> {{ index + 1 }}、 {{ item.sectionName }}</h3>
              <div v-for="(subitem,subindex) in item.subSections" :key="subitem.sectionId">
                {{ index + 1 }}-{{ subindex + 1 }}
                {{ subitem.sectionName }}
              </div>
            </div>
          </div>
        </el-tab-pane>
        <el-tab-pane label="评论" name="third">
          <div class="pinglun-box">
            <el-form ref="form" :model="form" label-width="80px">
              <div>评分</div>
              <el-form-item label="">
                <el-rate
                    v-model="form.score"
                    show-text>
                </el-rate>
              </el-form-item>
              <el-form-item label="">
                <el-input type="textarea" v-model="form.commentContent"></el-input>
              </el-form-item>
              <el-form-item>
                <el-button type="primary" @click="onSubmit">发表</el-button>
              </el-form-item>
            </el-form>
          </div>
        </el-tab-pane>
      </el-tabs>
    </div>
    <footer-page></footer-page>
  </div>
</template>

<style scoped lang="less">
.detai-main {

}

* {
  padding: 0;
  margin: 0;
}

::v-deep .el-form-item__content {
  margin-left: 0 !important;
}

.table-box {
  margin: auto;
  width: 1160px;
}

.course-detail {
  .course-box {
    display: flex;

    .img-box img {
      width: 330px;
      //height: 220px;
      border-radius: 12px;
    }

    padding: 20px;
    width: 1160px;
    margin: auto;
    margin-top: -100px;
  }

  .ruoter-box {
    font-size: 16px;
    padding: 20px 0 15px 20px;
    margin: auto;
    color: #fff;
    width: 1200px;
    height: 164px;
    background-size: 100%;
    background: -webkit-gradient(linear, left top, right top, from(#5782f6), to(#4683ff));
    background: linear-gradient(90deg, #5782f6, #4683ff);
    -webkit-box-shadow: 0 8px 10px 0 rgba(40, 113, 234, .1);
  }

  background: #f4f4f4;
}
</style>
